package com.blb.socket;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

public class MyClient {

    public void connect(String msg){
        //创建客户端连接
        //获得输出流
        try(Socket socket = new Socket("192.168.7.90",8888);
            DataInputStream in = new DataInputStream(socket.getInputStream());
            DataOutputStream out = new DataOutputStream(socket.getOutputStream())){
            //发送消息
            out.writeUTF(msg);
            out.flush();
            //读取消息
            String s = in.readUTF();
            System.out.println("服务器说：" + s);
        }catch (IOException ex){
            ex.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new MyClient().connect("Hello 你好啊！！！");
    }
}
